package com.qf.aop;



import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 切面类之 环绕通知 类
 * @author lixu
 */
public class MyMethodInterceptor implements MethodInterceptor {
     /**
     *环绕通知 方法
     * @param invocation
     * @return
     * @throws Throwable
     */

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("事务控制");
        System.out.println("日志打印");
        //核心代码
        Object result = null;
        try {
            Method method = invocation.getMethod();
            method.invoke(invocation.getThis(),invocation.getArguments());
            System.out.println("一切顺利：commit");
            return result;
        } catch (Exception e) {
            //e.printStackTrace();
            System.out.println("核心代码出来异常：rollback");
        }
        return result;
    }
}
